package com.bike.bikeserver.controller.backend;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.bike.bikeserver.common.annotation.OperationLog;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.Bike;
import com.bike.bikeserver.service.IBikeService;
import com.bike.bikeserver.service.impl.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.bike.bikeserver.constant.Constants.USER_RIGHT_EDIT;
import static com.bike.bikeserver.constant.Constants.USER_RIGHT_ALL;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/19 10:46
 */
@RestController
@RequestMapping("back/bike")
public class BackBikeController
{
    @Autowired
    IBikeService bikeService;
    @Autowired
    SysRoleService sysRoleService;

    /**
     * 获得全部单车信息
     *
     * @return
     */
    @GetMapping("getBikeList")
    public CommonResult getBikeList()
    {
        return bikeService.getBikeList();
    }

    /**
     * 根据单车名称模糊查询
     *
     * @param bikeName
     * @return
     */
    @OperationLog(value = "根据单车名称模糊查询单车信息:bike")
    @GetMapping("getBikeLikeName")
    public CommonResult getBikeLikeBikeName(@RequestParam("bikeName") String bikeName)
    {
        return bikeService.getBikeLikeBikeName(bikeName);
    }

    /**
     * 更新单车信息
     *
     * @param bike
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "根据id更新单车信息:bike")
    @PutMapping("editBikeById")
    public CommonResult editBikeById(@RequestBody Bike bike)
    {
        return bikeService.editBikeById(bike);
    }

    /**
     * 删除单车信息
     *
     * @param bike
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "根据id删除单车信息:bike")
    @DeleteMapping("deleteBikeById")
    public CommonResult deleteBikeById(@RequestBody Bike bike)
    {
        return bikeService.deleteBikeById(bike);
    }

    /**
     * 新增单车信息
     *
     * @param bike
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "新增单车信息:bike")
    @PostMapping("addBike")
    public CommonResult addBike(@RequestBody Bike bike)
    {
        return bikeService.addBike(bike);
    }


}
